Options:
-h, --help Print this message
+ --open Opens the docs in a browser after the operation
--no-deps Don't build documentation for dependencies
-j N, --jobs N The number of jobs to run in parallel
--features FEATURES Space-separated list of features to also build
let mut doc_opts = ops::DocOptions {
all: !options.flag_no_deps,
+ open_result: options.flag_open,
compile_opts: ops::CompileOptions {
env: if options.flag_no_deps {"doc"} else {"doc-all"},
shell: shell,
use core::source::Source;
use ops;
use sources::PathSource;
+use std::io::process::Command;
use util::{CargoResult, human};
pub struct DocOptions<'a> {
pub all: bool,
+ pub open_result: bool,
pub compile_opts: ops::CompileOptions<'a>,
}
}
try!(ops::compile(manifest_path, &mut options.compile_opts));
+
+ if options.open_result {
+ use std::io::fs::PathExtensions;
+
+ match lib_names.iter().nth(0).map(|l| package.get_absolute_target_dir()
+ .join("doc").join(*l).join("index.html"))
+ {
+ Some(ref path) if path.exists() => open_docs(path),
+ _ => ()
+ }
+ }
+
Ok(())
}
+
+#[cfg(not(any(target_os = "windows", target_os = "macos")))]
+fn open_docs(path: &Path) {
+ // trying xdg-open
+ match Command::new("xdg-open").arg(path).detached().status() {
+ Ok(_) => return,
+ Err(_) => ()
+ };
+
+ // trying gnome-open
+ match Command::new("gnome-open").arg(path).detached().status() {
+ Ok(_) => return,
+ Err(_) => ()
+ };
+
+ // trying kde-open
+ match Command::new("kde-open").arg(path).detached().status() {
+ Ok(_) => return,
+ Err(_) => ()
+ };
+}
+
+#[cfg(target_os = "windows")]
+fn open_docs(path: &Path) {
+ match Command::new("start").arg(path).detached().status() {
+ Ok(_) => return,
+ Err(_) => ()
+ };
+}
+
+#[cfg(target_os = "macos")]
+fn open_docs(path: &Path) {
+ match Command::new("open").arg(path).detached().status() {
+ Ok(_) => return,
+ Err(_) => ()
+ };
+}